/* 获取元素 */
const toggles = document.querySelectorAll(".toggle");
const good = document.querySelector("#good");
const cheap = document.querySelector("#cheap");
const fast = document.querySelector("#fast");
/* 循环toggles获取到toggles中的每个元素 */
toggles.forEach((toggle) =>
  /* 给每个元素添加上change事件 */
  toggle.addEventListener("change", (e) => doTheTrick(e.target))
);

const doTheTrick = (theClickedOne) => {
  /* good与cheap并且fast都为真的时候 */
  if (good.checked && cheap.checked && fast.checked) {
    /* 当前元素等good元素 */
    if (good === theClickedOne) {
      /* 将fast元素的checked属性置为false */
      fast.checked = false;
    }
    /* 当前元素等cheap元素 */
    if (cheap === theClickedOne) {
      /* 将good元素的checked属性置为false */
      good.checked = false;
    }
    /* 当前元素等fast元素 */
    if (fast === theClickedOne) {
      /* 将cheap元素的checked属性置为false */
      cheap.checked = false;
    }
  }
};
